package com.tbdp.lsmp.job;

import com.tbdp.lsmp.processor.ESQueryProcessor;
import com.tbdp.lsmp.processor.Processors;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;
import org.quartz.PersistJobDataAfterExecution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 * 选股程序任务,任务有状态，要保证当前任务结束之后才能运行后续任务
 *
 * @author xbkaishui
 * @version $Id: SelectStockJob.java, v 0.1 2017-11-05 下午10:35 xbkaishui Exp $$
 */
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class SelectStockJob implements Job {

    private static Logger logger = LoggerFactory.getLogger(SelectStockJob.class);


    /**
     * 执行周期选股模型运行
     */
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        // This job simply prints out its job name and the
        // date and time that it is running
        JobKey jobKey = context.getJobDetail().getKey();
        logger.info("SelectStockJob says: " + jobKey + " executing at " + new Date());
        long start = System.currentTimeMillis();
        ESQueryProcessor processor = Processors.getESQueryProcessor();
        processor.process();
        long end = System.currentTimeMillis();
        logger.info("one round cost {} ms ", (end - start));
    }
}
